// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package api_gateway

import (
	"context"
	"errors"
	"fmt"
	"net/http"
	"slices"

	"github.com/cloudflare/cloudflare-go/v6/internal/apijson"
	"github.com/cloudflare/cloudflare-go/v6/internal/param"
	"github.com/cloudflare/cloudflare-go/v6/internal/requestconfig"
	"github.com/cloudflare/cloudflare-go/v6/option"
)

// SettingSchemaValidationService contains methods and other services that help
// with interacting with the cloudflare API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewSettingSchemaValidationService] method instead.
type SettingSchemaValidationService struct {
	Options []option.RequestOption
}

// NewSettingSchemaValidationService generates a new service that applies the given
// options to each request. These options are applied after the parent client's
// options (if there is one), and before any request-specific options.
func NewSettingSchemaValidationService(opts ...option.RequestOption) (r *SettingSchemaValidationService) {
	r = &SettingSchemaValidationService{}
	r.Options = opts
	return
}

// Updates zone level schema validation settings on the zone
//
// Deprecated: Use
// [Schema Validation API](https://developers.cloudflare.com/api/resources/schema_validation/)
// instead.
func (r *SettingSchemaValidationService) Update(ctx context.Context, params SettingSchemaValidationUpdateParams, opts ...option.RequestOption) (res *SettingSchemaValidationUpdateResponse, err error) {
	opts = slices.Concat(r.Options, opts)
	if params.ZoneID.Value == "" {
		err = errors.New("missing required zone_id parameter")
		return
	}
	path := fmt.Sprintf("zones/%s/api_gateway/settings/schema_validation", params.ZoneID)
	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, params, &res, opts...)
	return
}

// Updates zone level schema validation settings on the zone
//
// Deprecated: Use
// [Schema Validation API](https://developers.cloudflare.com/api/resources/schema_validation/)
// instead.
func (r *SettingSchemaValidationService) Edit(ctx context.Context, params SettingSchemaValidationEditParams, opts ...option.RequestOption) (res *SettingSchemaValidationEditResponse, err error) {
	opts = slices.Concat(r.Options, opts)
	if params.ZoneID.Value == "" {
		err = errors.New("missing required zone_id parameter")
		return
	}
	path := fmt.Sprintf("zones/%s/api_gateway/settings/schema_validation", params.ZoneID)
	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &res, opts...)
	return
}

// Retrieves zone level schema validation settings currently set on the zone
//
// Deprecated: Use
// [Schema Validation API](https://developers.cloudflare.com/api/resources/schema_validation/)
// instead.
func (r *SettingSchemaValidationService) Get(ctx context.Context, query SettingSchemaValidationGetParams, opts ...option.RequestOption) (res *SettingSchemaValidationGetResponse, err error) {
	opts = slices.Concat(r.Options, opts)
	if query.ZoneID.Value == "" {
		err = errors.New("missing required zone_id parameter")
		return
	}
	path := fmt.Sprintf("zones/%s/api_gateway/settings/schema_validation", query.ZoneID)
	err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
	return
}

type SettingSchemaValidationUpdateResponse struct {
	// The default mitigation action used when there is no mitigation action defined on
	// the operation
	//
	// Mitigation actions are as follows:
	//
	// - `log` - log request when request does not conform to schema
	// - `block` - deny access to the site when request does not conform to schema
	//
	// A special value of of `none` will skip running schema validation entirely for
	// the request when there is no mitigation action defined on the operation
	ValidationDefaultMitigationAction SettingSchemaValidationUpdateResponseValidationDefaultMitigationAction `json:"validation_default_mitigation_action"`
	// When set, this overrides both zone level and operation level mitigation actions.
	//
	// - `none` will skip running schema validation entirely for the request
	// - `null` indicates that no override is in place
	ValidationOverrideMitigationAction SettingSchemaValidationUpdateResponseValidationOverrideMitigationAction `json:"validation_override_mitigation_action,nullable"`
	JSON                               settingSchemaValidationUpdateResponseJSON                               `json:"-"`
}

// settingSchemaValidationUpdateResponseJSON contains the JSON metadata for the
// struct [SettingSchemaValidationUpdateResponse]
type settingSchemaValidationUpdateResponseJSON struct {
	ValidationDefaultMitigationAction  apijson.Field
	ValidationOverrideMitigationAction apijson.Field
	raw                                string
	ExtraFields                        map[string]apijson.Field
}

func (r *SettingSchemaValidationUpdateResponse) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r settingSchemaValidationUpdateResponseJSON) RawJSON() string {
	return r.raw
}

// The default mitigation action used when there is no mitigation action defined on
// the operation
//
// Mitigation actions are as follows:
//
// - `log` - log request when request does not conform to schema
// - `block` - deny access to the site when request does not conform to schema
//
// A special value of of `none` will skip running schema validation entirely for
// the request when there is no mitigation action defined on the operation
type SettingSchemaValidationUpdateResponseValidationDefaultMitigationAction string

const (
	SettingSchemaValidationUpdateResponseValidationDefaultMitigationActionNone  SettingSchemaValidationUpdateResponseValidationDefaultMitigationAction = "none"
	SettingSchemaValidationUpdateResponseValidationDefaultMitigationActionLog   SettingSchemaValidationUpdateResponseValidationDefaultMitigationAction = "log"
	SettingSchemaValidationUpdateResponseValidationDefaultMitigationActionBlock SettingSchemaValidationUpdateResponseValidationDefaultMitigationAction = "block"
)

func (r SettingSchemaValidationUpdateResponseValidationDefaultMitigationAction) IsKnown() bool {
	switch r {
	case SettingSchemaValidationUpdateResponseValidationDefaultMitigationActionNone, SettingSchemaValidationUpdateResponseValidationDefaultMitigationActionLog, SettingSchemaValidationUpdateResponseValidationDefaultMitigationActionBlock:
		return true
	}
	return false
}

// When set, this overrides both zone level and operation level mitigation actions.
//
// - `none` will skip running schema validation entirely for the request
// - `null` indicates that no override is in place
type SettingSchemaValidationUpdateResponseValidationOverrideMitigationAction string

const (
	SettingSchemaValidationUpdateResponseValidationOverrideMitigationActionNone SettingSchemaValidationUpdateResponseValidationOverrideMitigationAction = "none"
)

func (r SettingSchemaValidationUpdateResponseValidationOverrideMitigationAction) IsKnown() bool {
	switch r {
	case SettingSchemaValidationUpdateResponseValidationOverrideMitigationActionNone:
		return true
	}
	return false
}

type SettingSchemaValidationEditResponse struct {
	// The default mitigation action used when there is no mitigation action defined on
	// the operation
	//
	// Mitigation actions are as follows:
	//
	// - `log` - log request when request does not conform to schema
	// - `block` - deny access to the site when request does not conform to schema
	//
	// A special value of of `none` will skip running schema validation entirely for
	// the request when there is no mitigation action defined on the operation
	ValidationDefaultMitigationAction SettingSchemaValidationEditResponseValidationDefaultMitigationAction `json:"validation_default_mitigation_action"`
	// When set, this overrides both zone level and operation level mitigation actions.
	//
	// - `none` will skip running schema validation entirely for the request
	// - `null` indicates that no override is in place
	ValidationOverrideMitigationAction SettingSchemaValidationEditResponseValidationOverrideMitigationAction `json:"validation_override_mitigation_action,nullable"`
	JSON                               settingSchemaValidationEditResponseJSON                               `json:"-"`
}

// settingSchemaValidationEditResponseJSON contains the JSON metadata for the
// struct [SettingSchemaValidationEditResponse]
type settingSchemaValidationEditResponseJSON struct {
	ValidationDefaultMitigationAction  apijson.Field
	ValidationOverrideMitigationAction apijson.Field
	raw                                string
	ExtraFields                        map[string]apijson.Field
}

func (r *SettingSchemaValidationEditResponse) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r settingSchemaValidationEditResponseJSON) RawJSON() string {
	return r.raw
}

// The default mitigation action used when there is no mitigation action defined on
// the operation
//
// Mitigation actions are as follows:
//
// - `log` - log request when request does not conform to schema
// - `block` - deny access to the site when request does not conform to schema
//
// A special value of of `none` will skip running schema validation entirely for
// the request when there is no mitigation action defined on the operation
type SettingSchemaValidationEditResponseValidationDefaultMitigationAction string

const (
	SettingSchemaValidationEditResponseValidationDefaultMitigationActionNone  SettingSchemaValidationEditResponseValidationDefaultMitigationAction = "none"
	SettingSchemaValidationEditResponseValidationDefaultMitigationActionLog   SettingSchemaValidationEditResponseValidationDefaultMitigationAction = "log"
	SettingSchemaValidationEditResponseValidationDefaultMitigationActionBlock SettingSchemaValidationEditResponseValidationDefaultMitigationAction = "block"
)

func (r SettingSchemaValidationEditResponseValidationDefaultMitigationAction) IsKnown() bool {
	switch r {
	case SettingSchemaValidationEditResponseValidationDefaultMitigationActionNone, SettingSchemaValidationEditResponseValidationDefaultMitigationActionLog, SettingSchemaValidationEditResponseValidationDefaultMitigationActionBlock:
		return true
	}
	return false
}

// When set, this overrides both zone level and operation level mitigation actions.
//
// - `none` will skip running schema validation entirely for the request
// - `null` indicates that no override is in place
type SettingSchemaValidationEditResponseValidationOverrideMitigationAction string

const (
	SettingSchemaValidationEditResponseValidationOverrideMitigationActionNone SettingSchemaValidationEditResponseValidationOverrideMitigationAction = "none"
)

func (r SettingSchemaValidationEditResponseValidationOverrideMitigationAction) IsKnown() bool {
	switch r {
	case SettingSchemaValidationEditResponseValidationOverrideMitigationActionNone:
		return true
	}
	return false
}

type SettingSchemaValidationGetResponse struct {
	// The default mitigation action used when there is no mitigation action defined on
	// the operation
	//
	// Mitigation actions are as follows:
	//
	// - `log` - log request when request does not conform to schema
	// - `block` - deny access to the site when request does not conform to schema
	//
	// A special value of of `none` will skip running schema validation entirely for
	// the request when there is no mitigation action defined on the operation
	ValidationDefaultMitigationAction SettingSchemaValidationGetResponseValidationDefaultMitigationAction `json:"validation_default_mitigation_action"`
	// When set, this overrides both zone level and operation level mitigation actions.
	//
	// - `none` will skip running schema validation entirely for the request
	// - `null` indicates that no override is in place
	ValidationOverrideMitigationAction SettingSchemaValidationGetResponseValidationOverrideMitigationAction `json:"validation_override_mitigation_action,nullable"`
	JSON                               settingSchemaValidationGetResponseJSON                               `json:"-"`
}

// settingSchemaValidationGetResponseJSON contains the JSON metadata for the struct
// [SettingSchemaValidationGetResponse]
type settingSchemaValidationGetResponseJSON struct {
	ValidationDefaultMitigationAction  apijson.Field
	ValidationOverrideMitigationAction apijson.Field
	raw                                string
	ExtraFields                        map[string]apijson.Field
}

func (r *SettingSchemaValidationGetResponse) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r settingSchemaValidationGetResponseJSON) RawJSON() string {
	return r.raw
}

// The default mitigation action used when there is no mitigation action defined on
// the operation
//
// Mitigation actions are as follows:
//
// - `log` - log request when request does not conform to schema
// - `block` - deny access to the site when request does not conform to schema
//
// A special value of of `none` will skip running schema validation entirely for
// the request when there is no mitigation action defined on the operation
type SettingSchemaValidationGetResponseValidationDefaultMitigationAction string

const (
	SettingSchemaValidationGetResponseValidationDefaultMitigationActionNone  SettingSchemaValidationGetResponseValidationDefaultMitigationAction = "none"
	SettingSchemaValidationGetResponseValidationDefaultMitigationActionLog   SettingSchemaValidationGetResponseValidationDefaultMitigationAction = "log"
	SettingSchemaValidationGetResponseValidationDefaultMitigationActionBlock SettingSchemaValidationGetResponseValidationDefaultMitigationAction = "block"
)

func (r SettingSchemaValidationGetResponseValidationDefaultMitigationAction) IsKnown() bool {
	switch r {
	case SettingSchemaValidationGetResponseValidationDefaultMitigationActionNone, SettingSchemaValidationGetResponseValidationDefaultMitigationActionLog, SettingSchemaValidationGetResponseValidationDefaultMitigationActionBlock:
		return true
	}
	return false
}

// When set, this overrides both zone level and operation level mitigation actions.
//
// - `none` will skip running schema validation entirely for the request
// - `null` indicates that no override is in place
type SettingSchemaValidationGetResponseValidationOverrideMitigationAction string

const (
	SettingSchemaValidationGetResponseValidationOverrideMitigationActionNone SettingSchemaValidationGetResponseValidationOverrideMitigationAction = "none"
)

func (r SettingSchemaValidationGetResponseValidationOverrideMitigationAction) IsKnown() bool {
	switch r {
	case SettingSchemaValidationGetResponseValidationOverrideMitigationActionNone:
		return true
	}
	return false
}

type SettingSchemaValidationUpdateParams struct {
	// Identifier.
	ZoneID param.Field[string] `path:"zone_id,required"`
	// The default mitigation action used when there is no mitigation action defined on
	// the operation
	//
	// Mitigation actions are as follows:
	//
	// - `log` - log request when request does not conform to schema
	// - `block` - deny access to the site when request does not conform to schema
	//
	// A special value of of `none` will skip running schema validation entirely for
	// the request when there is no mitigation action defined on the operation
	ValidationDefaultMitigationAction param.Field[SettingSchemaValidationUpdateParamsValidationDefaultMitigationAction] `json:"validation_default_mitigation_action,required"`
	// When set, this overrides both zone level and operation level mitigation actions.
	//
	// - `none` will skip running schema validation entirely for the request
	// - `null` indicates that no override is in place
	//
	// To clear any override, use the special value `disable_override` or `null`
	ValidationOverrideMitigationAction param.Field[SettingSchemaValidationUpdateParamsValidationOverrideMitigationAction] `json:"validation_override_mitigation_action"`
}

func (r SettingSchemaValidationUpdateParams) MarshalJSON() (data []byte, err error) {
	return apijson.MarshalRoot(r)
}

// The default mitigation action used when there is no mitigation action defined on
// the operation
//
// Mitigation actions are as follows:
//
// - `log` - log request when request does not conform to schema
// - `block` - deny access to the site when request does not conform to schema
//
// A special value of of `none` will skip running schema validation entirely for
// the request when there is no mitigation action defined on the operation
type SettingSchemaValidationUpdateParamsValidationDefaultMitigationAction string

const (
	SettingSchemaValidationUpdateParamsValidationDefaultMitigationActionNone  SettingSchemaValidationUpdateParamsValidationDefaultMitigationAction = "none"
	SettingSchemaValidationUpdateParamsValidationDefaultMitigationActionLog   SettingSchemaValidationUpdateParamsValidationDefaultMitigationAction = "log"
	SettingSchemaValidationUpdateParamsValidationDefaultMitigationActionBlock SettingSchemaValidationUpdateParamsValidationDefaultMitigationAction = "block"
)

func (r SettingSchemaValidationUpdateParamsValidationDefaultMitigationAction) IsKnown() bool {
	switch r {
	case SettingSchemaValidationUpdateParamsValidationDefaultMitigationActionNone, SettingSchemaValidationUpdateParamsValidationDefaultMitigationActionLog, SettingSchemaValidationUpdateParamsValidationDefaultMitigationActionBlock:
		return true
	}
	return false
}

// When set, this overrides both zone level and operation level mitigation actions.
//
// - `none` will skip running schema validation entirely for the request
// - `null` indicates that no override is in place
//
// To clear any override, use the special value `disable_override` or `null`
type SettingSchemaValidationUpdateParamsValidationOverrideMitigationAction string

const (
	SettingSchemaValidationUpdateParamsValidationOverrideMitigationActionNone            SettingSchemaValidationUpdateParamsValidationOverrideMitigationAction = "none"
	SettingSchemaValidationUpdateParamsValidationOverrideMitigationActionDisableOverride SettingSchemaValidationUpdateParamsValidationOverrideMitigationAction = "disable_override"
)

func (r SettingSchemaValidationUpdateParamsValidationOverrideMitigationAction) IsKnown() bool {
	switch r {
	case SettingSchemaValidationUpdateParamsValidationOverrideMitigationActionNone, SettingSchemaValidationUpdateParamsValidationOverrideMitigationActionDisableOverride:
		return true
	}
	return false
}

type SettingSchemaValidationEditParams struct {
	// Identifier.
	ZoneID param.Field[string] `path:"zone_id,required"`
	// The default mitigation action used when there is no mitigation action defined on
	// the operation Mitigation actions are as follows:
	//
	// - `log` - log request when request does not conform to schema
	// - `block` - deny access to the site when request does not conform to schema
	//
	// A special value of of `none` will skip running schema validation entirely for
	// the request when there is no mitigation action defined on the operation
	//
	// `null` will have no effect.
	ValidationDefaultMitigationAction param.Field[SettingSchemaValidationEditParamsValidationDefaultMitigationAction] `json:"validation_default_mitigation_action"`
	// When set, this overrides both zone level and operation level mitigation actions.
	//
	// - `none` will skip running schema validation entirely for the request
	//
	// To clear any override, use the special value `disable_override`
	//
	// `null` will have no effect.
	ValidationOverrideMitigationAction param.Field[SettingSchemaValidationEditParamsValidationOverrideMitigationAction] `json:"validation_override_mitigation_action"`
}

func (r SettingSchemaValidationEditParams) MarshalJSON() (data []byte, err error) {
	return apijson.MarshalRoot(r)
}

// The default mitigation action used when there is no mitigation action defined on
// the operation Mitigation actions are as follows:
//
// - `log` - log request when request does not conform to schema
// - `block` - deny access to the site when request does not conform to schema
//
// A special value of of `none` will skip running schema validation entirely for
// the request when there is no mitigation action defined on the operation
//
// `null` will have no effect.
type SettingSchemaValidationEditParamsValidationDefaultMitigationAction string

const (
	SettingSchemaValidationEditParamsValidationDefaultMitigationActionNone  SettingSchemaValidationEditParamsValidationDefaultMitigationAction = "none"
	SettingSchemaValidationEditParamsValidationDefaultMitigationActionLog   SettingSchemaValidationEditParamsValidationDefaultMitigationAction = "log"
	SettingSchemaValidationEditParamsValidationDefaultMitigationActionBlock SettingSchemaValidationEditParamsValidationDefaultMitigationAction = "block"
)

func (r SettingSchemaValidationEditParamsValidationDefaultMitigationAction) IsKnown() bool {
	switch r {
	case SettingSchemaValidationEditParamsValidationDefaultMitigationActionNone, SettingSchemaValidationEditParamsValidationDefaultMitigationActionLog, SettingSchemaValidationEditParamsValidationDefaultMitigationActionBlock:
		return true
	}
	return false
}

// When set, this overrides both zone level and operation level mitigation actions.
//
// - `none` will skip running schema validation entirely for the request
//
// To clear any override, use the special value `disable_override`
//
// `null` will have no effect.
type SettingSchemaValidationEditParamsValidationOverrideMitigationAction string

const (
	SettingSchemaValidationEditParamsValidationOverrideMitigationActionNone            SettingSchemaValidationEditParamsValidationOverrideMitigationAction = "none"
	SettingSchemaValidationEditParamsValidationOverrideMitigationActionDisableOverride SettingSchemaValidationEditParamsValidationOverrideMitigationAction = "disable_override"
)

func (r SettingSchemaValidationEditParamsValidationOverrideMitigationAction) IsKnown() bool {
	switch r {
	case SettingSchemaValidationEditParamsValidationOverrideMitigationActionNone, SettingSchemaValidationEditParamsValidationOverrideMitigationActionDisableOverride:
		return true
	}
	return false
}

type SettingSchemaValidationGetParams struct {
	// Identifier.
	ZoneID param.Field[string] `path:"zone_id,required"`
}
